package com.rm.zeyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rm.zeyou.constant.NumberConstants;
import com.rm.zeyou.entity.PayConfig;
import com.rm.zeyou.mapper.PayConfigMapper;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.PayConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rm.zeyou.util.check.CheckEmptyUtil;
import com.rm.zeyou.vo.response.SelectPayTypeResponseVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 支付方式配置表 服务实现类
 * </p>
 *
 * @author YanYang
 * @since 2025-04-09 10:27:55
 */
@Service
public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper, PayConfig> implements PayConfigService {
    @Resource
    private PayConfigMapper payConfigMapper;

    @Override
    public ApiRestResponse<List<SelectPayTypeResponseVo>> selectPayType() {
        List<PayConfig> payConfigs = payConfigMapper.selectList(new LambdaQueryWrapper<PayConfig>()
                .eq(PayConfig::getEnable, NumberConstants.ONE_CONSTANTS)
                .orderByAsc(PayConfig::getSort));
        List<SelectPayTypeResponseVo> responseVoList = new ArrayList<>();
        if (!CheckEmptyUtil.isEmpty(payConfigs)) {
            for (PayConfig payConfig : payConfigs) {
                SelectPayTypeResponseVo vo = new SelectPayTypeResponseVo();
                vo.setIcon(payConfig.getIcon());
                vo.setName(payConfig.getName());
                vo.setCode(payConfig.getCode());
                responseVoList.add(vo);
            }
        }
        return ApiRestResponse.success(responseVoList);
    }
}
